package edu.calvin.djs32.cs214.interpreters.frontend;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.Lexer;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.runtime.tree.Tree;
import org.norecess.antlr.IANTLRFrontEnd;

import edu.calvin.cs214.hobbes2008.HobbesTIR;

public class Hobbes2008FrontEnd implements IANTLRFrontEnd {

	public Lexer createLexer(String arg0) {
		return new Hobbes2008Lexer(new ANTLRStringStream(arg0));
	}

	public Hobbes2008Parser createParser(TokenStream arg0) {
		return new Hobbes2008Parser(arg0);
	}

	public Hobbes2008TIRBuilder createTreeParser(Tree arg0) {
		return new Hobbes2008TIRBuilder(new CommonTreeNodeStream(arg0));
	}

	public HobbesTIR process(CharStream stream) throws RecognitionException {
		Hobbes2008Parser parser = new Hobbes2008Parser(new CommonTokenStream(new Hobbes2008Lexer(stream)));
		return new Hobbes2008TIRBuilder(new CommonTreeNodeStream(parser.program().getTree())).expression();
	}

}
